import Router from 'koa-router';
import { PassThrough } from 'stream';
import { generate } from '../utils/index.js';
const check = new Router();

check.post('/', async(ctx) => {
    ctx.set({
        'Connection': 'keep-alive',
        'Cache-Control': 'no-cache',
        'Content-Type': 'text/event-stream',
    });
    const stream = new PassThrough();
    ctx.body = stream;
    ctx.status = 200;
    const data = ctx.request.body
    const prompt = `请纠正以下句子中的错误:“${data.text}”。`
    generate(prompt, [], (e) => {
        stream.write(JSON.stringify(e))
    }, () => {
        stream.end()
    })
})
export default check;
